home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Graphics / ImageFX / ImageIndex / ImageIndex.ifx < prev    next >
Encoding:
Text File  |  1998-08-21  |  12.5 KB  |  441 lines

  1. /*
  2. ** $VER: ImageIndex.ifx 1.0 (21.8.98)
  3. **
  4. ** Written by Michal Durys. In fact this is an extended version of
  5. ** Snapshot.ifx by Thomas Krehbiel. Send comments to: misha@femina.com.pl
  6. */
  7.  
  8. OPTIONS RESULTS
  9.  
  10. SIGNAL ON BREAK_C
  11.  
  12. GetMain
  13. IF rc = 0 THEN DO
  14.    RequestResponse 'The current buffer will be destroyed.'
  15.    IF rc ~= 0 THEN EXIT
  16.    END
  17.  
  18. KillBuffer Force
  19.  
  20. /* retreive defaults from any previous useage of this macro */
  21. defsdir  = GETCLIP('IFX_Snapshot_DefSource')
  22. defspat  = GETCLIP('IFX_Snapshot_DefSrcPat')
  23. defdest  = GETCLIP('IFX_Snapshot_DefDest')
  24. numcols  = GETCLIP('IFX_Snapshot_Colors')
  25. gridsize = GETCLIP('IFX_Snapshot_Grid')
  26. width    = GETCLIP('IFX_Snapshot_Width')
  27. height   = GETCLIP('IFX_Snapshot_Height')
  28. labelit  = GETCLIP('IFX_Snapshot_Labels')
  29. grey     = GETCLIP('IFX_Snapshot_Grey')
  30. keepext  = GETCLIP('IFX_Snapshot_KeepExt')
  31. saveform = GETCLIP('IFX_Snapshot_SaveForm')
  32. saveopt  = GETCLIP('IFX_Snapshot_SaveOpts')
  33. spacing  = GETCLIP('IFX_Snapshot_Spacing')
  34. enhance  = GETCLIP('IFX_Snapshot_Enhance')
  35. doback   = GETCLIP('IFX_Snapshot_DoBack')
  36. texture  = GETCLIP('IFX_Snapshot_Texture')
  37. backdrop = GETCLIP('IFX_Snapshot_Backdrop')
  38. doshadow = GETCLIP('IFX_Snapshot_DoShadow')
  39. red      = GETCLIP('IFX_Snapshot_Red')
  40. green    = GETCLIP('IFX_Snapshot_Green')
  41. blue     = GETCLIP('IFX_Snapshot_Blue')
  42. fontname = GETCLIP('IFX_Snapshot_Font')
  43. fontsize = GETCLIP('IFX_Snapshot_FontSize')
  44.  
  45. /* some defaults - change as desired */
  46.  
  47. IF defsdir  = '' THEN defsdir  = ""          /* default source dir */
  48. IF defspat  = '' THEN defspat  = "#?"        /* default source pattern */
  49. IF defdest  = '' THEN defdest  = "RAM:!katalog-" /* default dest files */
  50. IF numcols  = '' THEN numcols  = 8           /* colors in renderings */
  51. IF gridsize = '' THEN gridsize = 5           /* thumbnail rows/cols */
  52. IF width    = '' THEN width    = 640         /* dest width */
  53. IF height   = '' THEN height   = 480         /* dest height */
  54. IF labelit  = '' THEN labelit  = 1           /* label each thumbnail? */
  55. IF grey     = '' THEN grey     = 0           /* convert to greyscale? */
  56. IF keepext  = '' THEN keepext  = 0           /* keep file extensions? */
  57. IF saveform = '' THEN saveform = 'JPEG'      /* save format */
  58. IF saveopt  = '' THEN saveopt  = '85  '      /* save format */
  59. IF spacing  = '' THEN spacing  = 2           /* spacing between nails */
  60. IF enhance  = '' THEN enhance  = 1           /* enhance nails? */
  61. IF doback   = '' THEN doback   = 0           /* do backdrop texture? */
  62. IF texture  = '' THEN texture  = 0           /* apply texture? */
  63. IF backdrop = '' THEN backdrop = 'Textures/Leather'   /* backdrop texture */
  64. IF doshadow = '' THEN doshadow = 1           /* do shadowed nails? */
  65. IF red      = '' THEN red      = 24
  66. IF green    = '' THEN green    = 51
  67. IF blue     = '' THEN blue     = 93
  68. IF fontname = '' THEN fontname = 'Helvetica.font'
  69. IF fontsize = '' THEN fontsize = 11
  70.  
  71. RequestFile '"Source Directory:"' '"'defsdir'"' '" "' '"'defspat'"'
  72. IF rc ~= 0 THEN EXIT    /* cancelled */
  73. sourcedir = filereq.path
  74. sourcepat = filereq.pat
  75.  
  76. /* get a directory and pattern and grid size */
  77.  
  78. Gadget.1  = 'I/190/19/Rows & Columns:/'gridsize
  79. Gadget.2  = 'I/190/34/Spacing:/'spacing
  80.  
  81. Gadget.3  = 'I/190/50/Width (Pixels):/'width
  82. Gadget.4  = 'I/190/65/Height (Pixels):/'height
  83. Gadget.5  = 'T/190/80/60/0/Save Format:/'saveform
  84. Gadget.6  = 'T/190/95/60/0/Save Options:/'saveopt
  85. Gadget.7  = 'D/162/110/100/Colors:/9/2/4/8/16/32/64/128/254/24-Bit/'numcols
  86. Gadget.8  = 'T/110/125/140/1/Basename:/'defdest
  87.  
  88. Gadget.9  = 'X/300/20/Convert To Greyscale?/'grey
  89. Gadget.10 = 'X/300/32/Label Thumbnails?/'labelit
  90. Gadget.11 = 'X/300/44/Keep Extensions?/'keepext
  91. Gadget.12 = 'X/300/56/Enhance Thumbnails?/'enhance
  92. Gadget.13 = 'X/300/68/Create Shadows?/'doshadow
  93. Gadget.14 = 'X/300/80/Create Backdrop?/'doback
  94. Gadget.15 = 'X/300/92/Texture/'texture
  95.  
  96. Gadget.16 = 'T/300/104/180/0/ /'backdrop
  97.  
  98. Gadget.17 = 'J/300/125/35/R:/'red
  99. Gadget.18 = 'J/370/125/35/G:/'green
  100. Gadget.19 = 'J/440/125/35/B:/'blue
  101.  
  102. Gadget.20  = 'T/110/140/140/0/Font Name:/'fontname
  103. Gadget.21  = 'I/300/140/Size:/'fontsize
  104.  
  105. Gadget.23
  106.  
  107. ComplexRequest '"mSnapshot Options:"' 21 Gadget 520 185
  108. IF rc ~= 0 THEN EXIT
  109.  
  110. gridsize = result.1
  111. spacing  = result.2
  112. width    = result.3
  113. height   = result.4
  114. saveform = result.5
  115. saveopt  = result.6
  116. numcols  = result.7
  117. destbase = result.8
  118. grey     = result.9
  119. labelit  = result.10
  120. keepext  = result.11
  121. enhance  = result.12
  122. doshadow = result.13
  123. doback   = result.14
  124. texture  = result.15
  125. backdrop = result.16
  126. red      = result.17
  127. green    = result.18
  128. blue     = result.19
  129. fontname = result.20
  130. fontsize = result.21
  131.  
  132. CALL SETCLIP('IFX_Snapshot_DefSource', sourcedir)
  133. CALL SETCLIP('IFX_Snapshot_DefSrcPat', sourcepat)
  134. CALL SETCLIP('IFX_Snapshot_DefDest', destbase)
  135. CALL SETCLIP('IFX_Snapshot_Colors', numcols)
  136. CALL SETCLIP('IFX_Snapshot_Grid', gridsize)
  137. CALL SETCLIP('IFX_Snapshot_Width', width)
  138. CALL SETCLIP('IFX_Snapshot_Height', height)
  139. CALL SETCLIP('IFX_Snapshot_Labels', labelit)
  140. CALL SETCLIP('IFX_Snapshot_Grey', grey)
  141. CALL SETCLIP('IFX_Snapshot_KeepExt', keepext)
  142. CALL SETCLIP('IFX_Snapshot_SaveForm', saveform)
  143. CALL SETCLIP('IFX_Snapshot_SaveOpts', saveopt)
  144. CALL SETCLIP('IFX_Snapshot_Spacing', spacing)
  145. CALL SETCLIP('IFX_Snapshot_Enhance', enhance)
  146. CALL SETCLIP('IFX_Snapshot_DoBack', doback)
  147. CALL SETCLIP('IFX_Snapshot_Texture', texture)
  148. CALL SETCLIP('IFX_Snapshot_Backdrop', backdrop)
  149. CALL SETCLIP('IFX_Snapshot_DoShadow', doshadow)
  150. CALL SETCLIP('IFX_Snapshot_Red', red)
  151. CALL SETCLIP('IFX_Snapshot_Green', green)
  152. CALL SETCLIP('IFX_Snapshot_Blue', blue)
  153. CALL SETCLIP('IFX_Snapshot_Font', font)
  154. CALL SETCLIP('IFX_Snapshot_FontSize', fontsize)
  155.  
  156.  
  157. SELECT
  158.    WHEN numcols = 0 THEN numcols = 2
  159.    WHEN numcols = 1 THEN numcols = 4
  160.    WHEN numcols = 2 THEN numcols = 8
  161.    WHEN numcols = 3 THEN numcols = 16
  162.    WHEN numcols = 4 THEN numcols = 32
  163.    WHEN numcols = 5 THEN numcols = 64
  164.    WHEN numcols = 6 THEN numcols = 128
  165.    WHEN numcols = 7 THEN numcols = 256
  166.    WHEN numcols = 8 THEN numcols = 'DEEP'
  167.    OTHERWISE EXIT 0
  168.    END
  169.  
  170.  
  171. thumbxspace = (width / gridsize)
  172. thumbyspace = ((height-20) / gridsize)
  173.  
  174. thumbwidth = thumbxspace - spacing
  175. thumbheight = thumbyspace - spacing
  176.  
  177. picnum = 0
  178.  
  179.  
  180. DO FOREVER
  181.  
  182.    /* build list of files to process */
  183.  
  184.    ECHO 'List >RAM:__Snap_TEMP__ NOHEAD LFORMAT='sourcedir'/%s' sourcedir 'PAT' sourcepat
  185.    ADDRESS COMMAND 'List >RAM:__Snap_TEMP__ NOHEAD LFORMAT="'sourcedir'/%s" "'||sourcedir||'" PAT' sourcepat
  186.    IF rc ~= 0 THEN DO
  187.       RequestNotify 'Problem scanning the source directory.'
  188.       EXIT
  189.       END
  190.  
  191.    /* sort alphabetically */
  192.    ADDRESS COMMAND 'Sort RAM:__Snap_TEMP__ TO RAM:__Snap_LIST__'
  193.    ADDRESS COMMAND 'Delete RAM:__Snap_TEMP__ QUIET'
  194.  
  195.    /* okay, process the files */
  196.  
  197.    IF ~OPEN(infile, 'RAM:__Snap_LIST__', 'Read') THEN DO
  198.       RequestNotify 'Problem reading sorted file list - no files found?'
  199.       EXIT
  200.       END
  201.  
  202.    IF numcols ~= 'DEEP' THEN DO
  203.       SetRender 'Amiga'
  204.       Render Mode HIRES LACE
  205.       Render Colors numcols
  206.       Render Dither 1 2 0     /* floyd zigzag none */
  207.       END
  208.  
  209.    Requesters Off    /* disable error requesters */
  210.    Redraw Off
  211.    Undo Off
  212.  
  213.    Blend 100
  214.    EdgeMode Normal
  215.    Transparency Include 0 Exclude 0
  216.  
  217.    /* force new buffer the first time: */
  218.    x = 999
  219.    y = 999
  220.    pagenum = 0
  221.  
  222.    DO WHILE ~EOF(infile)
  223.  
  224.       x = x + 1
  225.       IF x >= gridsize THEN DO
  226.          x = 0
  227.          y = y + 1
  228.          IF y >= gridsize THEN DO
  229.  
  230.             GetMain
  231.             IF rc = 0 THEN DO
  232.                IF numcols ~= 'DEEP' THEN DO
  233.                   Render Go
  234.                   SaveRenderedAs saveform destbase||RIGHT('000'||picnum,3) saveopt
  235.                   Render Close
  236.                   END
  237.                ELSE DO
  238.                   SaveBufferAs saveform destbase||RIGHT('000'||picnum,3) saveopt
  239.                   END
  240.                END
  241.  
  242.             pagenum = pagenum + 1
  243.             picnum = picnum + 1
  244.  
  245.             IF grey THEN CreateBuffer width height 'GREY' red green blue FORCE
  246.             ELSE         CreateBuffer width height red green blue FORCE
  247.  
  248.             IF doback THEN DO
  249.                 IF texture THEN Hook ApplyTexture backdrop 0 80 Shiny
  250.             ELSE
  251.                 LoadBuffer backdrop FORCE 1
  252.             END
  253.  
  254.             title = 'Katalog #'||pagenum
  255.  
  256.             ActiveColor 0     /* usually black */
  257.             Text fontname fontsize 100 BOLD title
  258.             Blend 50
  259.             Point width%2+2 9
  260.             Blend 100
  261.             KillBrush
  262.  
  263.             ActiveColor 1     /* usually white */
  264.             Text fontname fontsize 100 BOLD title
  265.             Point width%2 7
  266.             KillBrush
  267.  
  268.             Redraw
  269.             y = 0
  270.  
  271.             END
  272.          END
  273.  
  274.       nextfile = READLN(infile)
  275.       IF nextfile = "" THEN ITERATE
  276.       Message nextfile
  277.  
  278.       xp = x*thumbxspace
  279.       yp = y*thumbyspace+20
  280.  
  281.       LoadBrush FILE nextfile 1       /* 1 in case we find an anim */
  282.  
  283.       IF rc = 0 THEN DO
  284.  
  285.          GetBrush
  286.          PARSE VAR result name w h d ax ay .
  287.  
  288.          IF grey THEN DO
  289.             IF (d > 1) THEN Color2Grey Luma
  290.             END
  291.  
  292.          IF (ax > 0) THEN h = h * ay % ax
  293.  
  294.          IF (w > h) THEN DO
  295.             nw = thumbwidth
  296.             nh = h * nw % w
  297.             IF (nh > thumbheight) THEN nh = thumbheight
  298.             END
  299.          ELSE DO
  300.             nh = thumbheight
  301.             nw = w * nh % h
  302.             IF (nw > thumbwidth) THEN nw = thumbwidth
  303.             END
  304.  
  305.          IF (w < thumbwidth) & (h < thumbheight) THEN
  306.             Scale nw nh FAST
  307.          ELSE
  308.             Scale nw nh
  309.  
  310.          /* a little enhancement - makes 'em stand out more */
  311.          IF enhance THEN DO
  312.             Contrast 10
  313.             UnsharpMask 8
  314.             END
  315.  
  316. /*
  317.          IF doshadow THEN DO
  318.             DrawMode Darken
  319.             EdgeMode FeatherIn 4
  320.             Point xp+thumbxspace%2+4 yp+thumbyspace%2+4
  321.             DrawMode Normal
  322.             EdgeMode Normal
  323.             END
  324. */
  325.  
  326.          /* Place thumbnail in a middle */
  327.          BrushHandle 0 0
  328.          IF w>h THEN
  329.              Point xp yp+((thumbheight-nh)%2)
  330.          ELSE
  331.              Point xp+((thumbwidth-nw)%2) yp
  332.  
  333.          KillBrush
  334.          END
  335.  
  336.       IF labelit THEN DO
  337.  
  338.          /* strip path and optionally the trailing extension */
  339.          n = LASTPOS('/', nextfile) + 1
  340.          label = SUBSTR(nextfile,n)
  341.          IF ~keepext THEN DO
  342.             n = 1
  343.             DO WHILE n > 0
  344.                n = LASTPOS('.', label)
  345.                IF (n > 0) THEN label = LEFT(label,n-1)
  346.                END
  347.             END
  348.  
  349. /*       What about putting some other gfx under each thumbnail?
  350.          ActiveColor 6
  351.          Box xp yp thumbwidth thumbheight
  352. */
  353.  
  354.          /* Draw dark box to make sure our label is visible */
  355.          DrawMode Darken 86
  356.          EdgeMode Normal
  357.          FilledBox xp+((thumbwidth-nw)%2) yp+thumbheight-(2*fontsize) nw 2*fontsize
  358.          DrawMode Normal
  359.  
  360.          /* Write with black pen */
  361.          ActiveColor 0     /* usually black */
  362.          /* Create brush */
  363.          Blend 50
  364.          Text fontname fontsize 100 label
  365.          GetBrush
  366.          PARSE VAR result dummyname textw texth
  367.          BrushHandle textw%2 texth
  368.          Point xp+thumbxspace%2+1 yp+thumbheight-fontsize+1
  369.          Blend 100
  370.          KillBrush
  371.  
  372.          /* Write with white pen */
  373.          ActiveColor 1     /* usually white */
  374.          Text fontname fontsize 100 label
  375.          GetBrush
  376.          PARSE VAR result dummyname textw texth
  377.          BrushHandle textw%2 texth
  378.          Point xp+thumbxspace%2 yp+thumbheight-fontsize
  379.          KillBrush
  380.  
  381.          /* These are the dimensions of our picture */
  382.          dims=w||'x'||h
  383.  
  384.          ActiveColor 0     /* usually black */
  385.          Text fontname fontsize 100 dims
  386.          Blend 50
  387.          GetBrush
  388.          PARSE VAR result dummyname textw texth
  389.          BrushHandle textw%2 texth
  390.          Point xp+thumbxspace%2+1 yp+thumbheight+1
  391.          Blend 100
  392.          KillBrush
  393.  
  394.          ActiveColor 1     /* usually white */
  395.          Text fontname fontsize 100 dims
  396.          GetBrush
  397.          PARSE VAR result dummyname textw texth
  398.          BrushHandle textw%2 texth
  399.          Point xp+thumbxspace%2 yp+thumbheight
  400.          KillBrush
  401.  
  402.          END
  403.  
  404.       Redraw xp yp thumbxspace thumbyspace
  405.  
  406.       END
  407.  
  408.    IF (x > 0) | (y > 0) THEN DO
  409.       IF numcols ~= 'DEEP' THEN DO
  410.          Render Go
  411.          SaveRenderedAs saveform destbase||RIGHT('000'||picnum,3) saveopt
  412.          Render Close
  413.          END
  414.       ELSE DO
  415.          SaveBufferAs saveform destbase||RIGHT('000'||picnum,3) saveopt
  416.          END
  417.       END
  418.  
  419.    RequestResponse 'Please insert next volume.'
  420.    IF rc ~= 0 THEN LEAVE
  421.  
  422.    CALL CLOSE(infile)
  423.  
  424.    KillBuffer Force
  425.  
  426.    END
  427.  
  428. BREAK_C:
  429.  
  430. CALL CLOSE(infile)
  431.  
  432. ADDRESS COMMAND 'Delete RAM:__Snap_LIST__ QUIET'
  433.  
  434. KillBrush
  435. Undo On
  436. Redraw On
  437. Requesters On
  438.  
  439. EXIT
  440.  
  441.